<?php

namespace app\admin\model;

use app\lib\Qiniu;

class Povertywork extends Base
{

    public static function _after_delete($id){  //删除图片记录及空间中的图片
        if(is_array($id)){
            $list = Image::where('relatedTable', 'article')->whereIn('relatedId', $id)->select();
        }else{
            $list = Image::where('relatedTable', 'article')->where('relatedId', $id)->select();
        }

        $Qiniu = new Qiniu();
        foreach ((array)$list as $v) {
            $key = substr(strrchr($v['imgUrl'], '/'), 1);
            $res = $Qiniu->delImg($key);  //删除图片
            Image::where('id',$v['id'])->delete();
        }
    }

    // 贫困户信息
    public function povertyMember() {
        return $this->belongsTo('member','povertymemberId');
    }

    // 帮扶人信息
    public function aidingMember() {
        return $this->belongsTo('Member','aidingId');
    }

    // 图片关联表
    public function image() {
        return $this->hasMany('Image','relatedId');
    }

    public function getTimeAttr($data){
        if(!$data){
            return '';
        }

        return substr(date('Y-m-d H:i:s', $data), 0, 10);
    }
}